<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: SWFObjectPortlet.php 292 2008-11-14 17:44:15Z steen.rabol@gmail.com $
 * @package Pradoportal.Portlets.ImagePortlet
 *
 */

Prado::using('Application.Portlets.Portlet');
Prado::using('Application.Common.Data.PortalConfigRecord');
/**
 * ImagePortlet front end
 *
 */
class SWFObjectPortlet extends Portlet
{
	const	PORTLET_CONFIG_PREFIX	= "SWFObjectPortlet_";
	private	$_portletconfig			= null;

	public function getPortletConfig()
	{
		return $this->_portletconfig;
	}

	public function getConfigName()
	{
		return self::PORTLET_CONFIG_PREFIX . $this->Parameters['id'];
	}

	public function onInit($param)
	{
		parent::onInit($param);

		try
		{
			$this->ConfigRecord = PortalConfigRecord::finder()->findByname($this->ConfigName);
			if($this->ConfigRecord === null)
			{
				$this->ConfigRecord			= new PortalConfigRecord();
				$this->ConfigRecord->name	= $this->ConfigName;
				$this->ConfigRecord->value	= Prado::serialize(array(
													"swfname"	=> "",
													"width"		=> "",
													"height"	=> "",
													"flashvars"	=> "",
													"quality"	=> "",
													"wmode"		=> "",
													"cssclass"	=> ""));

				$this->ConfigRecord->save();
			}
		}
		catch(Exception $e)
		{
			throw new PortalException(1,$e->getMessage());
		}

		$this->_portletconfig		= Prado::unserialize($this->ConfigRecord->value);
		$this->_portletconfig['id']	= $this->ConfigRecord->id;
	}

	public function onLoad($param)
	{
		parent::onLoad($param);

		if($this->PortletConfig !== null)
		{
			$imagefile = $this->Application->PortalBasePath . "/storage/media/" . $this->PortletConfig['swfname'];
			if(TPropertyValue::ensureString($this->PortletConfig['swfname']) != "" && file_exists($imagefile))
			{
				if(isset($this->PortletConfig['cssclass']) && $this->PortletConfig['cssclass'] !="")
					$this->pnlSWFObjectPortlet->CssClass=$this->PortletConfig['cssclass'];

				$this->swfobject->Visible		= true;
				$this->swfobject->Enabled		= true;
				$this->swfobject->MovieUrl		= $this->Application->Service->Request->BaseUrl . "/storage/media/" . $this->PortletConfig['swfname'];
				$this->swfobject->Width			= ($this->PortletConfig['width'] != "" ? $this->PortletConfig['width'] : '');
				$this->swfobject->Height		= ($this->PortletConfig['height'] != "" ? $this->PortletConfig['height']  : '');
				$this->swfobject->FlashVars		= "";
				$this->swfobject->Quality		= $this->PortletConfig['quality'];
				$this->swfobject->WMode			= $this->PortletConfig['wmode'];
			}
		}
	}
}
?>